//
//  MTDiscoverAPI.swift
//  MT
//
//  Created by ooops on 2020/5/18.
//  Copyright © 2020 张强. All rights reserved.
//

import Foundation
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MTCreateTaskAPI {
    /// 新增聚会任务
    case addTask(_ requestParameters: [String : Any])
    /// 修改聚会任务
    case editTask(_ requestParameters: [String : Any])
    /// 查询聚会任务详情
    case taskDetail(_ requestParameters: [String : Any])
    /// 查询聚会任务类型信息
    case partySubject
    /// 我的任务 / 报名任务
    case joinOrMineTask(_ requestParameters: [String : Any])
    /// 报名聚会任务
    case joinTask(_ requestParameters: [String : Any])
    /// 查询聚会任务申请信息
    case queryNotiy(_ requestParameters: [String : Any])
    /// 操作聚会任务人员
    case operateInvite(_ requestParameters: [String : Any])
    /// 查询聚会任务群发起者 / 参与者状态信息
    case queryPartyClubStatus(_ requestParameters: [String : Any])
    /// 聚会签到
    case partySign(_ req: [String : Any])
    /// 结束聚会任务
    case endParty(_ req: [String : Any])
    /// 服务器时间戳
    case timestamp
    /// 获取任务报名排名第一的数据
    case queryTopTask(_ req: [String : Any]? = nil)
    /// 查看聚会任务未读消息树
    case queryNotifyCount
    /// 群主发放聚会任务金
    case sendPartyTaskGift(_ req: [String : Any])
    /// 取消聚会任务
    case cancelPartyTask(_ req: [String : Any])
    
}

// MARK: ------------------  ----------------------
extension MTCreateTaskAPI: MTTargetType {
    /// 请求头
    var headers: [String : String]? {
        //return ["Access-Token": "I6w6XbQSWNQIsnB9zKFbtV7b"]
        return ["Access-Token": UserDefaults.MTUserCenter.token.storedString ?? ""]
    }

    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .addTask(_):
            return "/party-task/add"
        case .editTask(_):
            return "/party-task/edit"
        case .taskDetail(_):
            return "/party-task/getById"
        case .partySubject:
            return "/party-task/party-subject-type-list"
        case .joinOrMineTask(_):
            return "/party-task/queryPage"
        case .joinTask(_):
            return "/party-task-user/operate"
        case .queryNotiy(_):
            return "/party-task-user/queryNotifyPage"
        case .operateInvite(_):
            return "/party-task-user/operate"
        case .queryPartyClubStatus(_):
            return "/party-task/group-party-task-status"
        case .partySign(_):
            return "/party-task-user/sign-party-task"
        case .endParty(_):
            return "/party-task/end-party-task"
        case .timestamp:
            return "/system/getTimeStamp"
        case .queryTopTask(_):
            return "/party-task/queryHot"
        case .queryNotifyCount:
            return "/message/queryNotifyCount"
        case .sendPartyTaskGift(_):
            return "/party-task/sendGiftPartyTask"
        case .cancelPartyTask(_):
            return "/party-task/cancel-party-task"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
        case let .addTask(requestParameters):
            return requestParameters
        case let .editTask(requestParameters):
            return requestParameters
        case let .taskDetail(requestParameters):
            return requestParameters
        case .partySubject:
            return nil
        case let .joinOrMineTask(requestParameters):
            return requestParameters
        case let .joinTask(requestParameters):
            return requestParameters
        case let .queryNotiy(requestParameters):
            return requestParameters
        case let .operateInvite(requestParameters):
            return requestParameters
        case let .queryPartyClubStatus(requestParameters):
            return requestParameters
        case let .partySign(r):
            return r
        case let .endParty(r):
            return r
        case .timestamp:
            return nil
        case let .queryTopTask(r):
            return r
        case .queryNotifyCount:
            return nil
        case let .sendPartyTaskGift(r):
            return r
        case let .cancelPartyTask(r):
            return r
        }
    }
    
}
